package org.tmsps.ne4spring.base.ne;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.tmsps.ne4spring.utils.JsonUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * .分页
 * 
 * @author 刘华
 *
 */
@Data
public class NePage implements Serializable {
	private static final long serialVersionUID = -1936470346516905569L;

	/**
	 * .封装的查询字段
	 */
	public JSONObject srh = new JSONObject();
	private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	private int pageNumber = 1;
	private int pageSize = 20;
	private int totalPage = 1;
	private long totalRow = 0;

	public NePage() {

	}

	public NePage(int pageNumber, int pageSize) {
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
	}

	public NePage(List<Map<String, Object>> result, int pageNumber, int pageSize, int totalPage, int totalRow) {
		this.list = result;
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
		this.totalPage = totalPage;
		this.totalRow = totalRow;
	}

	// =======================get & set ====================================//

	// 计算分页第一条数据
	public int getStart() {
		return this.getPageSize() * (this.getPageNumber() - 1);
	}

	@Override
	public String toString() {
		return JsonUtil.toJson(this);
	}
}
